<?php
/**
 * 事件的组件demo
 */
namespace app\components;

use app\events\SaveEvent;
use yii\base\Component;

class EventComponent extends Component
{
    const EVENT_SAVE_BEFORE = 'save_before';

    public function save()
    {
        //$this->trigger(self::EVENT_SAVE_BEFORE);
        //触发事件 是使用自定义事件类对象触发事件
        $event = new SaveEvent();
        $event->msg = 'this is msg';
        $this->trigger(self::EVENT_SAVE_BEFORE, $event);
        echo "save\n";
    }

}